package com.zy.chat.controller;


import com.zy.chat.dto.LoginFormDTO;
import com.zy.chat.entity.UserLogin;
import com.zy.chat.service.LoginService;
import com.zy.chat.service.impl.UserLoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@Component
@RequestMapping(value = {"/logincontroller"})
public class LoginController {
    @Autowired
    private LoginService userLoginService;

    @PostMapping(value = "/login")
    public ResponseEntity<Map<String, Object>> login(@RequestBody LoginFormDTO loginFormDTO) throws Exception {

        Map<String, Object> login = this.userLoginService.login(loginFormDTO);
        return new ResponseEntity<Map<String, Object>>(login, HttpStatus.OK);
    }

    @GetMapping(value = "/getCode/{phone}")
    public ResponseEntity<Boolean> getCode(@PathVariable(value = "phone") String phone) {
        return new ResponseEntity<Boolean>(this.userLoginService.getCode(phone), HttpStatus.OK);
    }
}

